package com.whfc.emp.service.impl;

import com.whfc.common.exception.BizException;
import com.whfc.common.result.ResultEnum;
import com.whfc.emp.dao.AppEmpDayMapper;
import com.whfc.emp.dto.openapi.OpenApiEmpAttendDayDTO;
import com.whfc.emp.entity.AppEmpDay;
import com.whfc.emp.manager.AppEmpDataManager;
import com.whfc.emp.service.AppEmpDayService;
import org.apache.dubbo.config.annotation.DubboService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;

/**
 * @Description 人员每日数据统计
 * @Author hw
 * @Date 2021/1/5 16:42
 * @Version 1.0
 */
@DubboService(interfaceClass = AppEmpDayService.class, version = "1.0.0")
public class AppEmpDayServiceImpl implements AppEmpDayService {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private AppEmpDayMapper appEmpDayMapper;

    @Autowired
    private AppEmpDataManager appEmpDataManager;

    @Override
    public void initEmpDayData(Integer deptId, Date date) {
        appEmpDataManager.initEmpDayData(deptId, date);
    }

    @Override
    public void statEmpDayData(Integer deptId, Date date) {
        appEmpDataManager.statEmpDayData(deptId, date);
    }


    @Override
    public OpenApiEmpAttendDayDTO getOpenApiAttendDay(Integer empId, Date date) throws BizException {
        OpenApiEmpAttendDayDTO data = new OpenApiEmpAttendDayDTO();
        AppEmpDay appEmpDay = appEmpDayMapper.selectByEmpIdAndDate(empId, date);
        if (appEmpDay == null) {
            throw new BizException(ResultEnum.FAILURE.getCode(), "未找到该人员出勤信息");
        }
        data.setAttendState(appEmpDay.getAttendState());
        data.setEndTime(appEmpDay.getEndTime());
        data.setStartTime(appEmpDay.getStartTime());
        data.setWorkTimes(appEmpDay.getWorkTimes());
        return data;
    }
}
